package Model.DAO;

import Model.Beans.Answer;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Pashi
 */
public class AnswerDAO extends AbstracDAO<Answer> {
    
       public Answer getAnswer(int idAnswer){
        List<Answer> answers = buscar("idanswer="+idAnswer, Answer.class);
        if(answers!=null&&!answers.isEmpty()){
            return answers.get(0);
        }else{
            return null;
        }
    }
       public void deleteByQ(int idQ){
           try{
            session = HibernateUtil.getSessionFactory().openSession();
            transaccion = session.beginTransaction();
            Criteria actCri = session.createCriteria(Answer.class);
            actCri.add(Restrictions.eq("idquestion", idQ));
            session.delete(actCri);
            transaccion.commit();
            session.close();
        }catch(Exception e){
            transaccion.rollback();
            session.close();
        }

       }
    
}
